package com.algorithm.binarysearch;

public class BinarySearch {

    public static void main(String[] args) {
        Integer[] array = new Integer[]{1,2,3,4,5,6,7,8,9};
        System.out.println(binarySearch(array,array.length,10));
    }

    public static Integer binarySearch(Integer[] array, Integer length, Integer target) {
         int i=0,j=length-1;
         while(i<=j){
            int mid = (i+j)/2;
            if(array[mid]==target){
                return mid;
            } else if(array[mid]<target){
                i = mid+1;
                continue;
            }else {
                j = mid-1;
            }
         }
         return -1;
    }
}
